<template>
    <div id="index-statistic" :class="className" :style="{height:height,width:width}"></div>
</template>

<script>
    import echarts from 'echarts'
    export default {
        name: 'index-statistic',
        props: {
            className: {
                type: String,
                default: 'chart'
            },
            width: {
                type: String,
                default: '100%'
            },
            height: {
                type: String,
                default: '350px'
            },
            autoResize: {
                type: Boolean,
                default: true
            }
        },
        data () {
            return {
                chart: null,
                isResize:true,
            }
        },
        methods: {
            initChart() {
                this.chart = echarts.init(document.getElementById('index-statistic'));
                this.setOptions()
            },
            setOptions({} = {}) {
                this.chart.setOption({
                    tooltip: {
                        trigger: 'item',
                        formatter: '{a} <br/>{b}: {c} ({d}%)'
                    },
                    legend: {
                        orient: 'horizontal',
                        data: ['未达标指标 ', '已达指标']
                    },
                    series: [
                        {
                            name: '数据',
                            type: 'pie',
                            radius: ['50%', '70%'],
                            avoidLabelOverlap: false,
                            label: {
                                show: false,
                                position: 'center'
                            },
                            emphasis: {
                                label: {
                                    show: true,
                                    fontSize: '30',
                                    fontWeight: 'bold'
                                }
                            },
                            labelLine: {
                                show: false
                            },
                            data: [
                                {value: 50, name: '未达标指标'},
                                {value: 850, name: '已达指标'}
                            ]
                        }
                    ]
                });
                window.onresize = this.chart.resize;
            }
        },
        mounted () {
            this.initChart();
        }
    }
</script>

<style scoped>

</style>